package de.koller.worlders.engine.entity.zone;

import de.koller.worlders.engine.entity.mo.Elevator;
import de.koller.worlders.engine.entity.plattform.SolidPlattform;
import de.koller.worlders.engine.tiles.ITile;
import de.koller.worlders.engine.tiles.MOTile;
import de.koller.worlders.engine.tiles.data.ITileCreator;
import de.koller.worlders.render.VisualMap;
import de.koller.worlders.render.visual.DisplayRenderObject;

public class ElevatorZone extends ZoneEffect {
	public static final int GEN_ID = 3;
	
	public static final ITileCreator GEN_INSTANCE = new ITileCreator() {
		@Override public ITile newInstance() {
			return new Zone().addEffect( new ElevatorZone( true ) );
		}
		
		@Override public DisplayRenderObject getIcon() { return VisualMap.elevator; }
		@Override public String getName() { return "Fahrstuhl"; }
	};
	
	public static final ITileCreator GEN_INSTANCE_1 = new ITileCreator() {
		@Override public ITile newInstance() {
			return new Zone().addEffect( new ElevatorZone( false ) );
		}
		
		@Override public DisplayRenderObject getIcon() { return VisualMap.elevatorHozi; }
		@Override public String getName() { return "Horizontaler Fahrstuhl"; }
	};
	
	private Elevator elevator;
	private boolean vertical;

	public ElevatorZone( boolean vertical ) {
		this.vertical = vertical;
	}
	
	@Override
	public void init( Zone z ) {
		super.init( z );
		
		if( vertical )
			z.getTile().setVisual( VisualMap.elevator );
		else
			z.getTile().setVisual( VisualMap.elevatorHozi );
		
//		if( z.wroot != null && !z.wroot.getDebug().isActive() )
//			reset();
		
		if( z.root == null )
			return;
		
		elevator = new Elevator(	zone.getPosition().getXf() + .05f, 
									zone.getPosition().getYf() + .05f, 
									0.9f, 0.9f, 0x00000000, vertical );
		MOTile mot = new MOTile( SolidPlattform.GEN_INSTANCE.newInstance() );
		elevator.setMOTile( mot );
		zone.root.getEntityContainer().addChild( elevator );
	}

	@Override
	public void release() {
		super.release();
		
		elevator.removeMe();
//		if( zone.wroot.getEntityContainer().getElevators().remove( elevator ) )
//			elevator.removeMe();
	}

}
